##################################################################
#Execute o comando 'make' neste diretório para compilar o projeto#
##################################################################
# Entendendo o MakeFile
#
# $@ nome da regra
# $< nome da primeira dependência
# $^ lista de dependências
# $? lista de dependências mais recentes que a regra
# $* Nome do arquivo sem sufixo
#
##########################variáveis#############################
OPENCVDIR=/home/bradock/Programas/OpenCV/OpenCV-2.0.0
CC=g++
CXXFLAGS=-Wall -g -O3 -I /usr/include/SDL -I /usr/include/gtk-2.0 -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 `pkg-config --cflags glib-2.0`
OPENCVFLAGS=-I $(OPENCVDIR)/include/opencv 
LDFLAGS=-lm -lGL -lSDL -lSDLmain -lSDL_image -lSDL_ttf -lSDL_gfx -lSDL_mixer -lhighgui  -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 `pkg-config --libs glib-2.0` -lpthread
OPENCVLDFLAGS=-L $(OPENCVDIR)/release/lib 
OBJECTS=main.o Thread.o InputManager.o TimeCounter.o Text.o Audio.o TitleState.o PreGameState.o InitialState.o GameManager.o Sprite.o Animation.o SmileManager.o Smiley.o
OPENCVOBJECTS=TrackManager.o 
EXEC=game
#a variavel a sequir deve ser sobrescrita se deseja utilizar o TrackManager
#dando o comando "make OPENCV='true'"
OPENCV=


###########################regras###############################

all: $(EXEC)

$(EXEC): $(OBJECTS)
ifndef OPENCV
		@$(CC) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ 
else
		@$(CC) $(OPENCVFLAGS) $(CXXFLAGS) $(OPENCVLDFLAGS) $(LDFLAGS) -o $@ $^ $(OPENCVOBJECTS)
endif

Thread.o: Thread.cpp Thread.h
	@$(CC) $(CXXFLAGS) -o $@ -c $<

TrackManager.o: ;
ifdef OPENCV
	$(CC) $(CXXFLAGS) -o TrackManager.o -c TrackManager.cpp
endif

InputManager.o: InputManager.cpp InputManager.h Sprite.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<

TimeCounter.o: TimeCounter.cpp TimeCounter.h
	@$(CC) $(CXXFLAGS) -o $@ -c $<
	
Text.o: Text.cpp Text.h
	@$(CC) $(CXXFLAGS) -o $@ -c $<
	
Audio.o: Audio.cpp Audio.h
	@$(CC) $(CXXFLAGS) -o $@ -c $<

Smiley.o: Smiley.cpp Smiley.h Animation.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<
	
SmileManager.o: SmileManager.cpp SmileManager.h Animation.o Smiley.o TimeCounter.o Sprite.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<
	
Sprite.o: Sprite.cpp Sprite.h
	@$(CC) $(CXXFLAGS) -o $@ -c $<
	
Animation.o: Animation.cpp Animation.h Sprite.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<

TitleState.o: TitleState.cpp TitleState.h State.h Sprite.o Animation.o Text.o Audio.o InputManager.o TrackManager.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<
	
PreGameState.o: PreGameState.cpp PreGameState.h State.h Sprite.o Animation.o Text.o Audio.o InputManager.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<

InitialState.o: InitialState.cpp InitialState.h State.h Sprite.o Animation.o Text.o Audio.o InputManager.o TrackManager.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<

GameManager.o: GameManager.cpp GameManager.h State.h InitialState.o TitleState.o
	@$(CC) $(CXXFLAGS) -o $@ -c $<

main.o: main.cpp GameManager.h
	@$(CC) $(CXXFLAGS) -o $@ -c $<

.PHONY : clean mrproper

clean:
	rm -rf *.o

mrproper: clean
	rm -rf game
